/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rentalmobil.entity;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.ArrayList;
import java.util.List;
import rentalmobil.koneksidatabase.koneksiDataBase;

/**
 *
 * @author User
 */
public class Laporan_mobil extends dataMobil {

    int no_laporan;
    int id_mobil;
    String keterangan;
    Date tgl_servis;
    Date tgl_selesai;
    String biaya_servis;

    public Laporan_mobil() {
    }

    public int getNo_laporan() {
        return no_laporan;
    }

    public void setNo_laporan(int no_laporan) {
        this.no_laporan = no_laporan;
    }

    public int getId_mobil() {
        return id_mobil;
    }

    public void setId_mobil(int id_mobil) {
        this.id_mobil = id_mobil;
    }

    public String getKeterangan() {
        return keterangan;
    }

    public void setKeterangan(String keterangan) {
        this.keterangan = keterangan;
    }

    public Date getTgl_servis() {
        return tgl_servis;
    }

    public void setTgl_servis(Date tgl_servis) {
        this.tgl_servis = tgl_servis;
    }

    public Date getTgl_selesai() {
        return tgl_selesai;
    }

    public void setTgl_selesai(Date tgl_selesai) {
        this.tgl_selesai = tgl_selesai;
    }

    public String getBiaya_servis() {
        return biaya_servis;
    }

    public void setBiaya_servis(String biaya_servis) {
        this.biaya_servis = biaya_servis;
    }

    public boolean insertLaporanMobil() throws SQLException {
        PreparedStatement ps = koneksiDataBase.getConnection().prepareStatement("INSERT INTO laporan_mobil(no_plat_mobil,tgl_servis,tgl_selesai,biaya_servis,keterangan) VALUES (?,?,?,?,?)");
        ps.setString(1, getNo_plat_mobil());
        ps.setDate(2, new java.sql.Date(getTgl_servis().getTime()));
        ps.setDate(3, new java.sql.Date(getTgl_selesai().getTime()));
        ps.setString(4, getBiaya_servis());
        ps.setString(5, getKeterangan());
        ps.executeUpdate();
        return true;
    }

    public List<Laporan_mobil> viewTabelLaporanData() throws SQLException {
        Statement st = koneksiDataBase.getConnection().createStatement();
        ResultSet rs = st.executeQuery("SELECT no_laporan,no_plat_mobil,tgl_servis,tgl_selesai,biaya_servis,keterangan FROM laporan_mobil;");
        List<Laporan_mobil> list = new ArrayList<Laporan_mobil>();
        while (rs.next()) {
            Laporan_mobil dm = new Laporan_mobil();
            dm.setNo_laporan(rs.getInt("no_laporan"));
            dm.setNo_plat_mobil(rs.getString("no_plat_mobil"));
            dm.setTgl_servis(rs.getDate("tgl_servis"));
            dm.setTgl_selesai(rs.getDate("tgl_selesai"));
            dm.setBiaya_servis(rs.getString("biaya_servis"));
            dm.setKeterangan(rs.getString("keterangan"));
            list.add(dm);
        }
        return list;
    }
}
